/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                  *
 *        *************************************************         *
 *        *©2021-2031 HT  Corporation All rights reserved *         *
 *        *************************************************         *
 *                                                                  *
 * FileName    : h_pthread.h                                        *
 *                                                                  *
 * Author      : linus                                              *
 *                                                                  *
 * Email       : luoyaojun@haitutech.com                            *
 *                                                                  *
 * Date        : 2023-2-9                                           *
 *                                                                  *
 * Description :                                                    *
 *                                                                  *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef __HT_THREAD_H
#define __HT_THREAD_H

#include "ht_global.h"
#include "ht_type.h"

#define PTHREAD_WORK_MODE_ONCE		0
#define PTHREAD_WORK_MODE_ALWAYS	1

#define	PTHREAD_MAX_NAME		32

struct pthread_work;

typedef HT_S32 (*HT_PTHREAD_HANDLE)(struct pthread_work *pwork, HT_VOID *user);

struct ht_pthread
{
    const char *pthread_name;

    pthread_mutex_t work_list_mutex;

    struct pthread_work *pwork_head;

    HT_VOID *priv;
};

HT_S32 ht_pthread_init(struct ht_pthread *pthd_core, const char *name);
HT_S32 ht_pthread_work_set_timeout(struct ht_pthread *pthd_core, const char *name, HT_S32 timeout);
HT_S32 ht_pthread_request_work_always(struct ht_pthread *pthd_core, const char *name, HT_PTHREAD_HANDLE hdl,
                                        HT_VOID *argv);
HT_S32 ht_pthread_request_work_once(struct ht_pthread *pthd_core, const char *name, HT_PTHREAD_HANDLE hdl,
                                        HT_VOID *argv);
HT_S32 ht_pthread_work_stop(struct ht_pthread *pthd_core, const char *name);

HT_VOID ht_pthread_work_set_priv(struct pthread_work *pwork, HT_VOID *priv);

struct ht_pthread *ht_pthread_work_to_pthread(struct pthread_work *pwork);

#endif
